<template>
  <view class="content">
	  <view>
		  <u-swiper
		  	height="282"
		      :list="banners1"
		      :autoplay="false"
		      radius="20"
		      ></u-swiper>
	  </view>
		
		<view class="sub-page mx-2">
			<view class="bt-block p-4">
				<bg-title>工作台</bg-title>
				<view class="btn-area flex justify-between align-center mt-4">
					<view @tap="goto(item)" v-for="item in btns" :key="item.icon" class="flex flex-direction align-center justify-center">
						<u--image width="36" height="36" :src="item.icon"></u--image>
						<view class="btn-text">{{item.name}}</view>
					</view>
				</view>
			</view>
			<view class="mt-4">
				<u-swiper
					height="120"
				    :list="banners2"
				    :autoplay="false"
				    radius="20"
				    ></u-swiper>
			</view>
		</view>
		
  </view>
</template>

<script>
	import { getInfo, banners,  getMenus } from '../api/system/user.js'
  export default {
    onLoad() {
		// console.log(getApp().globalData.config)
		this.getBaseInfo()
		this.getBanner()
		this.getAppMenus()
		// uni.startPullDownRefresh();
    },
	onPullDownRefresh(){
		this.init()
		setTimeout(function () {
			uni.stopPullDownRefresh();
		}, 1000);
	},
	mounted() {
		uni.showTabBar()
		uni.$on("refresh-user", ()=>{
			this.getBaseInfo()
			this.getAppMenus()
		})
	},
	data(){
		return {
			banners1: [],
			banners2: [],
			btns:[
				{name:"入场管理", icon:"/static/images/ui/index/rcgl.png", url:"/pages/enter/index/index"},
				{name:"考勤管理", icon:"/static/images/ui/index/kqgl.png", url:"/pages/attendance/index"},
				{name:"薪酬管理", icon:"/static/images/ui/index/xcgl.png", url:"/pages/salary/index"},
				{name:"项目管理", icon:"/static/images/ui/index/xmgl.png", url:"/pages/project/index"},
				{name:"更多服务", icon:"/static/images/ui/index/gdfu.png", url:"/pages/more/index"},
			]
		}
	},
	methods:{
		init(){
			this.getBanner()
			this.getBaseInfo()
			this.getAppMenus()
		},
		goto(item){
			if(this.$store.state.user.userInfo.authStatus==0){
				this.$modal.confirm("请先进行实名认证", false).then(res=>{
					uni.navigateTo({
						url:"/pages/enter/verify/new"
					})
				})
				return false
			}
			if(this.$auth.hasPermi(item.name)){
				uni.navigateTo({
					url:item.url
				})
			} else {
				this.$modal.msg("您当前暂无权限")
			}
			
		},
		getBaseInfo(){
			getInfo().then(res=>{
				if(res.data){
					let _user = res.data
					this.$store.commit("SET_INFO", _user)
					this.$store.commit("SET_UID", _user.userId)
					this.$store.commit("SET_PID", _user.projectId)
					this.$store.commit("SET_NAME", _user.nickName)
					this.$store.commit("SET_GENDER", _user.gender)
					this.$store.commit("SET_PHONE", _user.phone)
					this.$store.commit("SET_IDCARD", _user.idCardNo)
					this.$store.commit("SET_ROLES", _user.roles||[])
				}
				
			})
		},
		getBanner(){
			banners().then(res=>{
				this.banners1 = res.data.upperList.map(b=>b.bannerUrl)
				this.banners2 = res.data.lowerList.map(b=>b.bannerUrl)
			})
		},
		getAppMenus(){
			getMenus().then(res=>{
				console.log(JSON.stringify(res.data))
				let menus = []
				menus=res.data
				this.$store.commit("SET_PERMISSIONS", menus)
			})
		}	
	}
  }
</script>

<style>
  .content {
    
  }

  .sub-page {  
	z-index: 100;
	position: relative;
	top:-50rpx;
  }
  .btn-text {
	  font-size: 24rpx;
	  margin-top: 12px;
  }
</style>
